package org.jshand.jxc.util;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Image;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.jshand.jxc.business.BusinessFrame;
import org.jshand.jxc.business.book.panel.LeftMenu;
import org.jshand.jxc.business.book.panel.StatusPanel;

public class SwingUtils {

	public static String ICONPATH = "icons/";
	private static BusinessFrame mainFrame;
	
	private static List<Component> contentList = new ArrayList();
	
	
	public static Image getImage(String filename){
		
		return getImageIcon(filename).getImage();
	}
	
	public static ImageIcon getImageIcon(String filename){
		
		URL url = ClassLoader.getSystemResource(ICONPATH+filename); 
		
		return new ImageIcon(url);
	}

	
	public static BusinessFrame getMainFrame() {
		return mainFrame;
	}

	public static void setMainFrame(BusinessFrame mainFrame) {
		SwingUtils.mainFrame = mainFrame;
	}

	public static void setMainFrame(JFrame mainFrame) {
		mainFrame = mainFrame;
	}
	
	
	public static  void setStatusMsg(String msg){
		mainFrame.setMsg(msg);
	}
	
	public static void addContentList(Component component){
		contentList.add(component);
	}
	
	public static void  addContentPanel(Component  content){
		Container root = mainFrame.getContentPane();
		for (Component com : contentList) {
			root.remove(com);
		}
		contentList.add(content);
		root.add(content, BorderLayout.CENTER);
		mainFrame.revalidate();
		mainFrame.repaint();
		
	}
	
	
	
	
	
}
